version 13
#delimit;
clear all;
set more off;
capture log close;


global strformat "%8.3f";

capture program drop sig_p;
program sig_p;
   args obj_var point_est_var point_sd_var p_val row_id_var row_num;
   local point_est `point_est_var';
   local point_sd `point_sd_var';
   if `p_val' > 0.1 {;
      replace `obj_var' = string(`point_est', "$strformat") if `row_id_var' == `row_num';
      };
   if `p_val' > 0.05 & `p_val' <= 0.1  {;
      replace `obj_var' = string(`point_est', "$strformat")+"*" if `row_id_var' == `row_num';
      };
   if `p_val' > 0.01 & `p_val' <= 0.05  {;
      replace `obj_var' = string(`point_est', "$strformat")+"**" if `row_id_var' == `row_num';
      };
   if `p_val' <= 0.01 {;
      replace `obj_var' = string(`point_est', "$strformat")+"***" if `row_id_var' == `row_num';
      };
   replace `obj_var' = "<" + string(`point_sd', "$strformat") + ">" + " " if `row_id_var' == `row_num' + 1;
   end;


*enter directory name here;

use "$dir/ReStat_children.dta", clear;



	
	
generate row_num = _n;

	
	
forvalues i=0/25 {;
	generate col`i' = "";
};

local row = 5;
sort row_num;
order col0-col25;



foreach var of varlist 
	ss2_num_days_operational ss2_open_admission ss6_uniform_required {;
	
	replace col0 = "`var'" if row_num == `row';

	su `var' if fu_child_level == 1 & fu_young_child == 1 & school_type_pprs == 1 &
		treatment_1 == 1 [aw=hh_weight];
	replace col2 = string(r(mean), "$strformat") if row_num == `row';
	replace col2 = "<" + string(r(sd), "$strformat") + ">" if row_num == `row' + 1;

	regress `var' treatment_2 if
		fu_child_level == 1 & fu_young_child == 1 & school_type_pprs == 1 &
		pooled_treatment == 1 [iw=hh_weight];
	est sto i_`row';

	local row = `row' + 2;
};

regress ss6_school_tuition_required treatment_2 if
	fu_child_level == 1 & fu_young_child == 1 & school_attended_by_child == 1 &
		school_type_pprs == 1
	[pw=hh_weight], cluster(villcode);
test treatment_2;
sig_p col3 _b[treatment_2] _se[treatment_2] r(p) row_num `row';	

local row = `row' + 2;

foreach var of varlist 
	ss2_language_sindhi ss2_language_english {;
	
	replace col0 = "`var'" if row_num == `row';

	su `var' if fu_child_level == 1 & fu_young_child == 1 & school_type_pprs == 1 &
		treatment_1 == 1 [aw=hh_weight];
	replace col2 = string(r(mean), "$strformat") if row_num == `row';
	replace col2 = "<" + string(r(sd), "$strformat") + ">" if row_num == `row' + 1;

	regress `var' treatment_2 if
		fu_child_level == 1 & fu_young_child == 1 & school_type_pprs == 1 &
		pooled_treatment == 1 [iw=hh_weight];
	est sto i_`row';

	local row = `row' + 2;
};

local row = `row' + 1;



gen pct_teachers_female = ss3_num_teachers_female/ss3_num_teachers;
gen pct_teachers_postsecondary = ss3_num_teachers_postsecondary/ss3_num_teachers;
gen pct_teachers_5years = ss3_num_teachers_5years/ss3_num_teachers;
gen pct_teachers_5to10years = ss3_num_teachers_5to10years/ss3_num_teachers;
gen pct_teachers_10years = ss3_num_teachers_10years/ss3_num_teachers;


foreach var of varlist 
	ss3_num_teachers 
	pct_teachers_female
	pct_teachers_postsecondary
	pct_teachers_5years
	pct_teachers_5to10years
	pct_teachers_10years
	ss3_avg_absent_2more {;
	
	replace col0 = "`var'" if row_num == `row';

	su `var' if fu_child_level == 1 & fu_young_child == 1 & school_type_pprs == 1 &
		treatment_1 == 1 [aw=hh_weight];
	replace col2 = string(r(mean), "$strformat") if row_num == `row';
	replace col2 = "<" + string(r(sd), "$strformat") + ">" if row_num == `row' + 1;

	regress `var' treatment_2 if
		fu_child_level == 1 & fu_young_child == 1 & school_type_pprs == 1 &
		pooled_treatment == 1 [iw=hh_weight];
	est sto i_`row';
	
	local row = `row' + 2;
};


local row = `row' + 1;


foreach var of varlist 
	ss4_* {;
	
	replace col0 = "`var'" if row_num == `row';

	su `var' if fu_child_level == 1 & fu_young_child == 1 & school_type_pprs == 1 &
		treatment_1 == 1 [aw=hh_weight];
	replace col2 = string(r(mean), "$strformat") if row_num == `row';
	replace col2 = "<" + string(r(sd), "$strformat") + ">" if row_num == `row' + 1;

	regress `var' treatment_2 if
		fu_child_level == 1 & fu_young_child == 1 & school_type_pprs == 1 &
		pooled_treatment == 1 [iw=hh_weight];
	est sto i_`row';
	
	local row = `row' + 2;
};

local row = 5;

generate student_teacher_ratio = (ss5_num_boys + ss5_num_girls)/ss3_num_teachers;

foreach var of varlist 
	ss5_num_boys ss5_num_girls ss5_pct_students_female student_teacher_ratio {;
	
	replace col5 = "`var'" if row_num == `row';

	su `var' if fu_child_level == 1 & fu_young_child == 1 & school_type_pprs == 1 &
		treatment_1 == 1 [aw=hh_weight];
	replace col7 = string(r(mean), "$strformat") if row_num == `row';
	replace col7 = "<" + string(r(sd), "$strformat") + ">" if row_num == `row' + 1;

	regress `var' treatment_2 if
		fu_child_level == 1 & fu_young_child == 1 & school_type_pprs == 1 &
		pooled_treatment == 1 [iw=hh_weight];
	est sto ib_`row';
	
	local row = `row' + 2;
};


local row = `row' + 1;


foreach var of varlist 
	ss9_days_absent ss9_female
	ss9_age ss9_education ss9_monthly_salary ss9_years_teaching
	ss9_years_teaching_thischool {;
	
	replace col5 = "`var'" if row_num == `row';

	su `var' if fu_child_level == 1 & fu_young_child == 1 & school_type_pprs == 1 &
		treatment_1 == 1 [aw=hh_weight];
	replace col7 = string(r(mean), "$strformat") if row_num == `row';
	replace col7 = "<" + string(r(sd), "$strformat") + ">" if row_num == `row' + 1;

	regress `var' treatment_2 if
		fu_child_level == 1 & fu_young_child == 1 & school_type_pprs == 1 &
		pooled_treatment == 1 [iw=hh_weight];
	est sto ib_`row';
	
	local row = `row' + 2;
};


local row = `row' + 1;


foreach var of varlist 
	ss9_hours_teaching ss9_hrs_teaching_wholeclass ss9_hrs_teaching_smallgroup
	ss9_hrs_teaching_individual ss9_hrs_teaching_notes ss9_hrs_teaching_discipline
	ss9_hrs_teaching_testing ss9_hrs_teaching_admin  {;
	
	replace col5 = "`var'" if row_num == `row';

	su `var' if fu_child_level == 1 & fu_young_child == 1 & school_type_pprs == 1 &
		treatment_1 == 1 [aw=hh_weight];
	replace col7 = string(r(mean), "$strformat") if row_num == `row';
	replace col7 = "<" + string(r(sd), "$strformat") + ">" if row_num == `row' + 1;

	regress `var' treatment_2 if
		fu_child_level == 1 & fu_young_child == 1 & school_type_pprs == 1 &
		pooled_treatment == 1 [iw=hh_weight];
	est sto ib_`row';
	
	local row = `row' + 2;
};


suest i_* ib_*, cluster(villcode);


local row = 5;


foreach var of varlist 
	ss2_num_days_operational ss2_open_admission ss6_uniform_required {;
	
	test [i_`row'_mean]treatment_2;
	sig_p col3 _b[i_`row'_mean:treatment_2] _se[i_`row'_mean:treatment_2] r(p) row_num `row';
	
	local row = `row' + 2;
	
};

local row = `row' + 2;

foreach var of varlist 
	ss2_language_sindhi ss2_language_english {;
	
	test [i_`row'_mean]treatment_2;
	sig_p col3 _b[i_`row'_mean:treatment_2] _se[i_`row'_mean:treatment_2] r(p) row_num `row';
	
	local row = `row' + 2;
	
};


local row = `row' + 1;


foreach var of varlist 
	ss3_num_teachers 
	pct_teachers_female
	pct_teachers_postsecondary
	pct_teachers_5years
	pct_teachers_5to10years
	pct_teachers_10years
	ss3_avg_absent_2more {;
	
	test [i_`row'_mean]treatment_2;
	sig_p col3 _b[i_`row'_mean:treatment_2] _se[i_`row'_mean:treatment_2] r(p) row_num `row';
	
	local row = `row' + 2;

};


local row = `row' + 1;



foreach var of varlist 
	ss4_* {;

	test [i_`row'_mean]treatment_2;
	sig_p col3 _b[i_`row'_mean:treatment_2] _se[i_`row'_mean:treatment_2] r(p) row_num `row';
	
	local row = `row' + 2;

};


local row = 5;



foreach var of varlist 
	ss5_num_boys ss5_num_girls ss5_pct_students_female student_teacher_ratio {;
	
	test [ib_`row'_mean]treatment_2;
	sig_p col8 _b[ib_`row'_mean:treatment_2] _se[ib_`row'_mean:treatment_2] r(p) row_num `row';
	
	local row = `row' + 2;
	
};


local row = `row' + 1;



foreach var of varlist 
	ss9_days_absent ss9_female
	ss9_age ss9_education ss9_monthly_salary ss9_years_teaching
	ss9_years_teaching_thischool {;
	
	test [ib_`row'_mean]treatment_2;
	sig_p col8 _b[ib_`row'_mean:treatment_2] _se[ib_`row'_mean:treatment_2] r(p) row_num `row';
	
	local row = `row' + 2;

};


local row = `row' + 1;



foreach var of varlist 
	ss9_hours_teaching ss9_hrs_teaching_wholeclass ss9_hrs_teaching_smallgroup
	ss9_hrs_teaching_individual ss9_hrs_teaching_notes ss9_hrs_teaching_discipline
	ss9_hrs_teaching_testing ss9_hrs_teaching_admin  {;
	
	test [ib_`row'_mean]treatment_2;
	sig_p col8 _b[ib_`row'_mean:treatment_2] _se[ib_`row'_mean:treatment_2] r(p) row_num `row';
	
	local row = `row' + 2;

};



local row = `row' + 10;


outsheet col0-col8 using "$dir/Table A2 School Char By gender_differentiated treatment (SUR).csv"
	if row_num < `row', comma replace;
